package com.omesoft.hksnore.util.newsnore;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeUtil {
	public String getNowDate() {
		Date currentTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmssSSS");// yyyyMMddhhmmssSSS,yyyy-MM-dd
																				// HH:mm:ss
		String dateString = formatter.format(currentTime);
		return dateString;
	}

	public String getTimeStr(long curTime) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmssSSS");
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(curTime);
		String timeStr = sdf.format(calendar.getTime());
		return timeStr;

	}

	public long getSec(String curTime) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long curTimeMs = 0;
		try {
			curTimeMs = sdf.parse(curTime).getTime();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return curTimeMs;

	}

	public long getMs(String curTime) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmssSSS");
		long curTimeMs = 0;
		try {
			curTimeMs = sdf.parse(curTime).getTime();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return curTimeMs;

	}

	public String getHMS(long dur) {
		int s = (int) ((dur / 1000) % 60);
		int m = (int) (dur / 60000);
		int h = (int) (dur / 3600000);
		String sDur = "T:" + ((h > 9) ? "" : 0) + h + ":" + ((m > 9) ? "" : 0)
				+ m + ":" + ((s > 9) ? "" : 0) + s;
		return sDur;
	}
}
